/*
 * 作者:熊猫
 * 日期:2017 - 3 - 16 3 - 47 - 52
 *
 */

package net.lainiao.morethread.Chapter7.demo2;

import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/16.
 */
public class MyPriorityTask implements Runnable,Comparable<MyPriorityTask> {
    private int priority;
    private String name;
    public MyPriorityTask(String name,int priority){
        this.name=name;
        this.priority=priority;
    }
    @Override
    public int compareTo(MyPriorityTask o) {
        if(this.priority<o.priority){
            return 1;
        }
        if(this.priority>o.priority){
            return -1;
        }
        return 0;
    }

    @Override
    public void run() {
        System.out.println("MyPriority Task Name "+this.name+" for priority "+this.priority);
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
